////////////////////////////////////////////////////////////////
// filename: world.cpp
// description: source file for the world objects class
// author: Jay Tomten (jaytomten@gmail.com)
// notes:

// namespace

// defines

// includes
#include <SDL/SDL_image.h>
#include <SDL/SDL.h>
#include "object.h"
#include <stdlib.h>
#include <math.h>
#include "story.h"
#include "level.h"
#include <iostream>

// globals

////////////////////////////////////////////////////////////////
// constructor
Story::Story()
    {

    // use Init() or alt constructor

    }

////////////////////////////////////////////////////////////////
// alternate constructor that calls Init()
Story::Story(int type, float x, float y, float z)
    {

    Init(type, x, y, z);

    }

////////////////////////////////////////////////////////////////
// destructor
Story::~Story()
    {

    glDeleteTextures(1, &texture);

    delete v;


    }

////////////////////////////////////////////////////////////////
// Init() - set up the world we want
void Story::Init(int type, float x, float y, float z)
    {

    size = 0;
    state = STATE_NORM;
    power = 0.0;
    range = 0.0;
    life = 0.0;
    team = TEAM_NEUTRAL;
    pos.Init(x, y, z);
    SDL_Surface *bg2;

    // there must be a better way!
    switch(type)
        {
        case STORY_1:
            t = STORY_1;
            cout << "Loading story 1";
            bg2 = IMG_Load("../res/story/level1.png");
            break;

        case STORY_2:

            t = STORY_2;
            cout << "Loading story 2";
            bg2 = IMG_Load("../res/story/level2.png");
            break;

        case STORY_3:

            t = STORY_3;
            cout << "Loading story 3";
            bg2 = IMG_Load("../res/story/level3.png");
            break;

        case STORY_4:

            t = STORY_4;
            cout << "Loading story 4";
            bg2 = IMG_Load("../res/story/level4.png");
            break;

        case STORY_5:

            t = STORY_5;
            cout << "Loading story 5";
            bg2 = IMG_Load("../res/story/level5.png");
            break;

        case STORY_6:

            t = STORY_6;
            cout << "Loading story 6";
            bg2 = IMG_Load("../res/story/level6.png");
            break;

        case STORY_7:

            t = STORY_7;
            cout << "Loading story 1";
            bg2 = IMG_Load("../res/story/level7.png");
            break;

        case STORY_8:
            cout << "Loading story 8";
            bg2 = IMG_Load("../res/story/level8.png");
            break;

        default:
            break;
        }

    if(bg2->w > 0)
        {
        glDeleteTextures(1, &texture);
        glGenTextures(1, &texture); // lets build the texture!
        glBindTexture(GL_TEXTURE_2D, texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg2->w, bg2->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg2->pixels);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        }
    SDL_FreeSurface(bg2);
    }

////////////////////////////////////////////////////////////////
// Update() - update one story item
bool Story::Update(float d)
    {


            if  (d > 2)
                {
                // no activities yet...
                }

    return true;

    }

////////////////////////////////////////////////////////////////
// Draw() - draw one world item
void Story::Draw()
    {

    glPushMatrix();
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture);

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f);
    glVertex3f(-50.0f, 25.0f, pos.z);
    glTexCoord2f(0.0f,1.0f);
    glVertex3f(-50.0f,  -25.0f, pos.z);
    glTexCoord2f(1.0f,1.0f);
    glVertex3f( 50.0f,  -25.0f, pos.z);
    glTexCoord2f(1.0f,0.0f);
    glVertex3f( 50.0f, 25.0f, pos.z);
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glPopMatrix();

    }










